<template>
  <div class="goods-add">
    <van-sticky>
      <van-nav-bar :title="$route.meta.title" left-arrow @click-left="onClickLeft" style="width:100%;" />
    </van-sticky>
    <van-form @submit="onSubmit">
      <van-cell-group class="goods-add-items">
        <van-field label="优先级" v-model="sort" type="number" placeholder="请输入商品类型优先级，如：1、2" input-align="right" />
        <van-field label="商品类型" v-model="typename" placeholder="请输入商品类型名称" input-align="right" />
      </van-cell-group>
      <div class="goods-add-set">
        <div class="set-center">
          <van-button round type="info" native-type="submit" color="#1bb89c">新 增</van-button>
        </div>
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
  name: 'GoodsAdd',
  data () {
    return {
      disabled: false,
      showSellway: false,
      sort: '',
      typename: '',
    };
  },
  methods: {
    onClickLeft () {
      this.$router.push({ name: 'goods' })
    },
    onSubmit () {
      this.$axios("/products/createprodtype", {
        sort: this.sort,
        type_name: this.typename,
      })
        .then((res) => {
          if (res.data.code == 1) {
            Toast.success('添加成功')
            setTimeout(() => {
              this.$router.push({ name: "goods" })
            }, 1000);
          } else {
            Toast.fail('添加失败')
          }
        })
        .catch((err) => {
          console.error('参数错误' + err);
        });
    },
  },
}
</script>
<style lang="less" scoped>
.goods-add {
  display: flex;
  flex-direction: column;
  &-items {
    width: 100%;

    /deep/ .van-field__label {
      color: black;
    }
  }
  &-set {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 100px auto;
    .set-center {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 100%;
      margin: 0 auto;
      .set-spacing {
        height: 30px;
      }
      /deep/ .van-button {
        width: 30%;
        height: 80px;
        font-weight: bold;
        font-size: 30px;
      }
    }
  }
}
</style>